<!DOCTYPE html>
<html>
<head th:replace="_header_include::frag(~{::title},~{::style},~{})">
	<title>后台管理系统</title>
    <meta charset="UTF-8">
    <style>
        .dayTimeEnd .el-form-item__label:before{display: none;}
        .days .el-form-item__error{padding-left: 165px;}
        .timeToLine{display: block;float: left;margin-right: 2px;height: 34px;line-height: 34px;}
        .el-form-item{margin-bottom: 15px;}
    </style>
</head>
<body>
<div id="addOptimizeRule" class="addOptimizeRule mainPadding" style="display: none;">  
    <el-breadcrumb separator="/" class="elBreadcrumb marginB20">
        <el-breadcrumb-item>Home</el-breadcrumb-item>
        <el-breadcrumb-item>资源管理</el-breadcrumb-item>
        <el-breadcrumb-item>优化分配规则管理</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="inforTitle">新建优化分配规则</div> 
    <el-form :model="form" :rules="rules" ref="form">
        <div class="borderbox padding20">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="规则名称：" prop="ruleName" :label-width="formLabelWidth">
                        <el-input v-model="form.ruleName" autocomplete="off" style="width: 300px;" maxlength="50"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="行业类别：" prop="industryCategory" :label-width="formLabelWidth">
                        <el-select v-model="form.industryCategory" reserve-keyword=true filterable   multiple placeholder="请选择" style="width: 300px;">
                            <el-option
                                v-for="item in industryOptions"
                                :key="item.value"
                                :label="item.name"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>                
                <el-col :span="12">
                    <el-form-item label="规则有效开始时间：" prop="startTime" :label-width="formLabelWidth">
                        <el-date-picker type="datetime" placeholder="选择日期时间" v-model="form.startTime" style="width: 300px;"></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="规则有效结束时间：" prop="endTime" :label-width="formLabelWidth">
                        <el-date-picker type="datetime" placeholder="选择日期时间" v-model="form.endTime" style="width: 300px;"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>                
                <el-col :span="12">   
                    <el-form-item label="周期内设定有效日：" :label-width="formLabelWidth" class="days" style="float: left;">
                        <em class="requiredRed" style="left: -120px;">*</em>
                        <el-radio v-model="form.radio" label="0" @change="changeDays">每天</el-radio>
                        <el-radio v-model="form.radio" label="1" @change="changeDays" style="margin: 0 10px 0 15px;">特殊设定</el-radio>
                    </el-form-item>             
                    <el-form-item label="" prop="days" :label-width="0" v-show="showDays" style="float: left;">
                        <el-select v-model="form.days"  filterable  multiple placeholder="请选择" style="width: 135px;">
                            <el-option
                                v-for="item in weeksOptions"
                                :key="item.value"
                                :label="item.name"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="有效日内时间范围：" prop="dayTimeStart" :label-width="formLabelWidth" style="width: 318px;float: left;">
                        <el-time-picker type="datetime" placeholder="选择时间" v-model="form.dayTimeStart" style="width: 135px;" format="HH:mm:ss" value-format="HH:mm:ss"></el-time-picker>
                    </el-form-item>
                    <span class="timeToLine">——</span>
                    <el-form-item label="" prop="dayTimeEnd" class="dayTimeEnd" style="width: 175px;float: left;">
                        <el-time-picker type="datetime" placeholder="选择时间" v-model="form.dayTimeEnd" style="width: 135px;" format="HH:mm:ss" value-format="HH:mm:ss"></el-time-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="媒介：" prop="source" :label-width="formLabelWidth">
                        <el-select v-model="form.source" reserve-keyword=true filterable  multiple placeholder="请选择" style="width: 300px;" @change="changeSource">
                            <el-option
                                v-for="item in sourceOptions"
                                :key="item.value"
                                :label="item.name"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="资源类别：" prop="category" :label-width="formLabelWidth">
                        <el-select v-model="form.category" multiple placeholder="请选择" style="width: 300px;">
                            <el-option
                                v-for="item in categoryOptions"
                                :key="item.value"
                                :label="item.name"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <!-- 显示新增的标签 -->
            <el-row>
                <el-col :span="12">
                    <el-form-item label="" :label-width="formLabelWidth" style="    margin-bottom: 0;">
                        <el-tag
                            v-for="tag in tags1"
                            :key="tag"
                            closable
                            @close="deleteFun1(tag)"
                            style="margin-right: 10px;">
                            {{tag}}
                        </el-tag>
                    </el-form-item>
                </el-col>
                <el-col :span="12" style="float: right;">
                    <el-form-item label="" :label-width="formLabelWidth" style="    margin-bottom: 0;">
                        <el-tag
                            v-for="tag in tags2"
                            :key="tag"
                            closable
                            @close="deleteFun2(tag)"
                            style="margin-right: 10px;">
                            {{tag}}
                        </el-tag>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="包含搜索词：" :label-width="formLabelWidth" style="float: left;">
                        <el-input v-model="form.searchWord" autocomplete="off"  maxlength="50" style="width: 224px;margin-right: 6px;"></el-input>                            
                    </el-form-item>
                    <el-form-item style="float: left;">
                        <el-button type="primary" @click="addFun1">添加</el-button>           
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="不包含搜索词：" :label-width="formLabelWidth" style="float: left;">
                        <el-input v-model="form.notSearchWord" autocomplete="off"  maxlength="50" style="width: 224px;margin-right: 6px;"></el-input>
                    </el-form-item>
                    <el-form-item style="float: left;">
                        <el-button type="primary" @click="addFun2">添加</el-button>           
                    </el-form-item>
                </el-col>
            </el-row>
            <!-- 显示新增的标签 -->
            <el-row>
                <el-col :span="12">
                    <el-form-item label="" :label-width="formLabelWidth" style="    margin-bottom: 0;">
                        <el-tag
                            v-for="tag in tags3"
                            :key="tag"
                            closable
                            @close="deleteFun3(tag)"
                            style="margin-right: 10px;">
                            {{tag}}
                        </el-tag>
                    </el-form-item>
                </el-col>
                <el-col :span="12" style="float: right;">
                    <el-form-item label="" :label-width="formLabelWidth" style="    margin-bottom: 0;">
                        <el-tag
                            v-for="tag in tags4"
                            :key="tag"
                            closable
                            @close="deleteFun4(tag)"
                            style="margin-right: 10px;">
                            {{tag}}
                        </el-tag>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="包含省：" :label-width="formLabelWidth" style="float: left;">
                        <el-input v-model="form.province" autocomplete="off"  maxlength="50" style="width: 224px;margin-right: 6px;"></el-input>                            
                    </el-form-item>
                    <el-form-item style="float: left;">
                        <el-button type="primary" @click="addFun3">添加</el-button>           
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="不包含省：" :label-width="formLabelWidth" style="float: left;">
                        <el-input v-model="form.notProvince" autocomplete="off"  maxlength="50" style="width: 224px;margin-right: 6px;"></el-input>
                    </el-form-item>
                    <el-form-item style="float: left;">
                        <el-button type="primary" @click="addFun4">添加</el-button>           
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-form-item label="是否启用：" prop="isUse" :label-width="formLabelWidth">
                    <el-select v-model="form.status" placeholder="请选择" style="width:300px;">
                        <el-option
                            v-for="item in statusOptions"
                            :key="item.value"
                            :label="item.name"
                            :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-row>   
            <el-form-item label="选择电销组/经纪组：" prop="chooseTeam" :label-width="formLabelWidth" class="marginBottom15">
                <span style="position: absolute;left: -125px;color: #f56c6c;">*</span>
                <el-button type="primary" @click="addDomain">添加电销组/经纪组</el-button>
            </el-form-item>
            <el-table :data="form.teleRuleTeamList" style="width: 100%;margin-bottom: 20px" border>
                <el-table-column type="index" align="center" prop="rank" label="序号" width="55"></el-table-column>
                <el-table-column align="center" prop="businessLine" label="业务线*">
                    <template slot-scope="scope">
                            <el-form-item :prop="'teleRuleTeamList.' + scope.$index + '.businessLine'" :rules='rules.businessLine' style="width: 160px;margin:0 auto;height: 57px;">
                            <el-select filterable v-model="scope.row.businessLine" placeholder="请选择" @change="getTeleGroupList(scope.$index, form.teleRuleTeamList)">
                                <el-option
                                    v-for="item in businessLineOptions"
                                    :key="item.businessLine"
                                    :label="item.name"
                                    :value="item.businessLine">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="orgId" label="电销组/经纪组*">
                    <template slot-scope="scope">
                            <el-form-item :prop="'teleRuleTeamList.' + scope.$index + '.orgId'" :rules='rules.orgId' style="width: 160px;margin:0 auto;height: 57px;">
                            <el-select filterable v-model="scope.row.orgId" placeholder="请选择">
                                <el-option
                                    v-for="item in scope.row.teleOptions"
                                    :key="item.id+','+item.orgType"
                                    :label="item.name"
                                    :value="item.id+','+item.orgType">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="proportion" label="比例*" width="130">
                    <span style="color: #f56c6c;">*</span>
                    <template slot-scope="scope">
                        <el-form-item :prop="'teleRuleTeamList.' + scope.$index + '.proportion'" :rules='rules.proportion' style="width: 100px;margin:0 auto;height: 57px;">
                            <el-input @keyup.native.prevent="resourceMaxNumber(scope.$index, form.teleRuleTeamList)" v-model="scope.row.proportion"></el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="resourceMaxNum" label="资源条数*" width="160">
                    <template slot-scope="scope">
                        <el-form-item :prop="'teleRuleTeamList.' + scope.$index + '.resourceMaxNum'" :rules='rules.resourceMaxNum' style="width: 130px;margin:0 auto;height: 57px;">
                            <!-- input值 -->
                            <el-input @keyup.native.prevent="resourceMaxNumber1(scope.$index, form.teleRuleTeamList)" v-model="scope.row.resourceMaxNum" ></el-input>
                            <!-- 不限按钮    -->
                            <el-button type="primary" size="mini" style="position: absolute;top: 6px;right: 4px;z-index: 2;" @click="unlimitedBtn(scope.$index, form.teleRuleTeamList)" >不限</el-button>
                            <!-- 不限input -->
                            <el-input style="position: absolute;top: 0;right: 0;z-index: 1;" @focus="unlimitedIpt(scope.$index, form.teleRuleTeamList)"  v-if="scope.row.unlimitedShow" v-model="scope.row.unlimited"></el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="isPrior" label="优先分配*" width="130">
                    <template slot-scope="scope">
                            <el-form-item :prop="'teleRuleTeamList.' + scope.$index + '.isPrior'" :rules='rules.isPrior' style="width: 100px;margin:0 auto;height: 57px;">
                            <el-select v-model="scope.row.isPrior" placeholder="请选择">
                                <el-option
                                    v-for="item in priorOptions"
                                    :key="item.value"
                                    :label="item.name"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="接收时间段">
                    <template slot-scope="scope">
                        <el-form-item label="" :prop="'teleRuleTeamList.' + scope.$index + '.orgDayTimeStart'" label-width="0" style="width: 70px;display: inline-block;">
                            <el-time-picker type="datetime" placeholder="选择时间" v-model="scope.row.orgDayTimeStart" style="width: 70px;" format="HH:mm:ss" value-format="HH:mm:ss" :editable="false" :clearable="false"></el-time-picker>
                        </el-form-item>
                        <span>—</span>
                        <el-form-item label="" :prop="'teleRuleTeamList.' + scope.$index + '.orgDayTimeEnd'" style="width: 70px;display: inline-block;">
                            <el-time-picker type="datetime" placeholder="选择时间" v-model="scope.row.orgDayTimeEnd" style="width: 70px;" format="HH:mm:ss" value-format="HH:mm:ss" :editable="false" :clearable="false"></el-time-picker>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="projectId" label="资源项目归属">
                    <template slot-scope="scope">
                        <el-form-item :prop="'teleRuleTeamList.' + scope.$index + '.ascriptionProjectId'" :rules='rules.projectId' style="width: 160px;margin:0 auto;height: 57px;">
                            <el-select filterable clearable v-model="scope.row.ascriptionProjectId" placeholder="请选择">
                                <el-option
                                        v-for="item in noSingProjectList"
                                        :key="item.id"
                                        :label="item.projectName"
                                        :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="操作" width="70">
                    <template slot-scope="scope">
                        <el-button @click.native.prevent="deleteRow(scope.$index, form.teleRuleTeamList)" type="text" size="small">删除</el-button>
                    </template>
            	</el-table-column>
            </el-table>
            <el-form-item label="选择话务组/顾问组：" prop="chooseTeam" :label-width="formLabelWidth" class="marginBottom15">
                <span style="position: absolute;left: -125px;color: #f56c6c;">*</span>
                <el-button type="primary" @click="addDomainTraffic">添加话务组/顾问组</el-button>
            </el-form-item>
            <el-table :data="form.trafficRuleTeamList" style="width: 100%" border>
                <el-table-column type="index" align="center" prop="rank" label="序号" width="55"></el-table-column>
                <el-table-column align="center" prop="orgId" label="话务组/顾问组*">
                    <template slot-scope="scope">
                            <el-form-item :prop="'trafficRuleTeamList.' + scope.$index + '.orgId'" :rules='rules.orgId' style="width: 160px;margin:0 auto;height: 57px;">
                            <el-select filterable v-model="scope.row.orgId" placeholder="请选择">
                                <el-option
                                    v-for="item in trafficOptions"
                                    :key="item.id+','+item.orgType"
                                    :label="item.name"
                                    :value="item.id+','+item.orgType">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="proportion" label="比例*">
                    <span style="color: #f56c6c;">*</span>
                    <template slot-scope="scope">
                        <el-form-item :prop="'trafficRuleTeamList.' + scope.$index + '.proportion'" :rules='rules.proportion' style="width: 160px;margin:0 auto;height: 57px;">
                            <el-input @keyup.native.prevent="resourceMaxNumber(scope.$index, form.teleRuleTeamList)" v-model="scope.row.proportion"></el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="resourceMaxNum" label="资源条数*"  width="160" >
                    <template slot-scope="scope">
                        <el-form-item :prop="'trafficRuleTeamList.' + scope.$index + '.resourceMaxNum'" :rules='rules.resourceMaxNum' style="width: 130px;margin:0 auto;height: 57px;">
                            <!-- input值 -->
                            <el-input @keyup.native.prevent="resourceMaxNumber1(scope.$index, form.trafficRuleTeamList)" v-model="scope.row.resourceMaxNum" ></el-input>
                            <!-- 不限按钮    -->
                            <el-button type="primary" size="mini" style="position: absolute;top: 6px;right: 4px;z-index: 2;" @click="unlimitedBtn(scope.$index, form.trafficRuleTeamList)" >不限</el-button>
                            <!-- 不限input -->
                            <el-input style="position: absolute;top: 0;right: 0;z-index: 1;" @focus="unlimitedIpt(scope.$index, form.trafficRuleTeamList)"  v-if="scope.row.unlimitedShow" v-model="scope.row.unlimited"></el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="isPrior" label="优先分配*">
                    <template slot-scope="scope">
                            <el-form-item :prop="'trafficRuleTeamList.' + scope.$index + '.isPrior'" :rules='rules.isPrior' style="width: 130px;margin:0 auto;height: 57px;">
                            <el-select v-model="scope.row.isPrior" placeholder="请选择">
                                <el-option
                                    v-for="item in priorOptions"
                                    :key="item.value"
                                    :label="item.name"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="接收时间段">
                    <template slot-scope="scope">
                        <el-form-item label="" :prop="'trafficRuleTeamList.' + scope.$index + '.orgDayTimeStart'" label-width="0" style="width: 70px;display: inline-block;">
                            <el-time-picker type="datetime" placeholder="选择时间" v-model="scope.row.orgDayTimeStart" style="width: 70px;" format="HH:mm:ss" value-format="HH:mm:ss" :editable="false" :clearable="false"></el-time-picker>
                        </el-form-item>
                        <span>—</span>
                        <el-form-item label="" :prop="'trafficRuleTeamList.' + scope.$index + '.orgDayTimeEnd'" style="width: 70px;display: inline-block;">
                            <el-time-picker type="datetime" placeholder="选择时间" v-model="scope.row.orgDayTimeEnd" style="width: 70px;" format="HH:mm:ss" value-format="HH:mm:ss" :editable="false" :clearable="false"></el-time-picker>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="projectId" label="资源项目归属">
                    <template slot-scope="scope">
                        <el-form-item :prop="'trafficRuleTeamList.' + scope.$index + '.ascriptionProjectId'" :rules='rules.projectId' style="width: 160px;margin:0 auto;height: 57px;">
                            <el-select filterable clearable v-model="scope.row.ascriptionProjectId" placeholder="请选择">
                                <el-option
                                        v-for="item in noSingProjectList"
                                        :key="item.id"
                                        :label="item.projectName"
                                        :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="操作" width="120">
                    <template slot-scope="scope">
                        <el-button @click.native.prevent="deleteRow(scope.$index, form.trafficRuleTeamList)" type="text" size="small">删除</el-button>
                    </template>
            	</el-table-column>
            </el-table>
            <div class="padding20 f-tac">            
                <el-button type="primary" :disabled="submitDisabled" @click="submitForm('form')">确认</el-button>
                <el-button @click="cancelForm()">取 消</el-button>
            </div> 
        </div>        
    </el-form>  
</div>
</body>
<!-- import Vue before Element -->
<div th:include="_footer_include :: #jsLib"></div>
<script th:inline="javascript">
var noSingProjectList =[[${noSingProjectList}]];
var clueCategoryList=[[${clueCategoryList}]];//资源类别集合
var industryCategoryList=[[${industryCategoryList}]];//行业类别集合
var mediumList=[[${mediumList}]];//媒介集合
var trafficList=[[${trafficList}]];//话务组集合
var businessLineList=[[${businessLineList}]];//业务线集合
    var aorVM = new Vue({
        el: '#addOptimizeRule',
        data: function() {
            return {                
                form: {
                    ruleName:'',
                    startTime:'',
                    endTime:'',
                    industryCategory:[],
                    source:[],
                    category:[],
                    searchWord:'',
                    notSearchWord:'',
                    province:'',
                    notProvince:'',
                    status:1,
                    teleRuleTeamList: [
                        // {
                        //      orgId:'',
                        //      proportion:'',
                        //      resourceMaxNum:'',
                        //      isPrior:'',
                        //      unlimited:'',//不限文字
                        //      unlimitedVal:'',//不限-1取值
                        //      unlimitedShow:false,//是否显示不限input
                        // }
                    ],
            		trafficRuleTeamList: [
                        // {
                        //      orgId:'',
                        //      proportion:'',
                        //      resourceMaxNum:'',
                        //      isPrior:'',
                        //      unlimited:'',//不限文字
                        //      unlimitedVal:'',//不限-1取值
                        //      unlimitedShow:false,//是否显示不限input
                        // }
                    ],                                      
                    radio:"0",//默认选每天
                    days:[],
                    dayTimeStart:"00:00:00",
                    dayTimeEnd:"23:59:59",
                },
                weeksOptions:[{
                    value: "2",
                    name: '星期一'
                },{
                    value: "3",
                    name: '星期二'
                },{
                    value: "4",
                    name: '星期三'
                },{
                    value: "5",
                    name: '星期四'
                },{
                    value: "6",
                    name: '星期五'
                },{
                    value: "7",
                    name: '星期六'
                },{
                    value: "1",
                    name: '星期日'
                }],
                showDays:false,//默认不显示星期  
                formLabelWidth: '180px',
                rules:{
                    ruleName: [
                        { required: true, message: '请输入规则名称', trigger: 'blur' }
                    ],
                    startTime: [
                        { required: true, message: '请选择规则有效开始时间', trigger: 'blur' }
                    ],
                    endTime: [
                        { required: true, message: '请选择规则有效结束时间', trigger: 'blur' }
                    ],
                    industryCategory: [
                        {  required: true, message: '请至少选择一个行业类别', trigger: 'change' }
                    ],
                    source: [
                        { required: true, message: '请至少选择一个媒介', trigger: 'change' }
                    ],
                    category: [
                        { required: true, message: '请至少选择一个资源类别', trigger: 'change' }
                    ],
                    status: [
                        { required: true, required: true, message: '请选择是否启用', trigger: 'change' }
                    ],                    
                    chooseTeam: [
                                 { validator:function(rule,value,callback){
                                     if(aorVM.form.teleRuleTeamList.length==0&&aorVM.form.trafficRuleTeamList.length==0){
                                         callback(new Error("请添加电销组/经纪组或话务组/顾问组"));
                                         return;
                                     }
                                     callback();
                                 }, trigger: 'change'}
                             ],                    
                    orgId: [
                        { required: true, required: true, message: '请选择电销组/经纪组', trigger: 'change' }
                    ],
                    businessLine: [
                                   { required: true, required: true, message: '请选择业务线', trigger: 'change' }
                               ],
                    proportion: [
                        { required: true, required: true, message: '请输入比例', trigger: 'change'},
                        { validator:function(rule,value,callback){               
                            if(/^[0-9]*$/.test(value) == false){
                               callback(new Error("请输入整数数字"));
                            }else{
                               callback();
                            } 
                            callback();
                        }, trigger: 'change'}
                    ],
                    resourceMaxNum: [
                        { required: true, required: true, message: '请添加资源条数', trigger: 'change' },
                        { validator:function(rule,value,callback){               
                            if(/^[0-9]*$/.test(value) == false){
                               callback(new Error("请输入整数数字"));
                            }else{
                               callback();
                            } 
                            callback();
                        }, trigger: 'change'}
                    ],
                    days: [
                        { validator:function(rule,value,callback){
                            if(aorVM.form.radio!=="0"&&aorVM.form.days.length==0){
                               callback(new Error("请选择星期"));
                            }else{
                               callback();
                            } 
                        }, trigger: 'change'}
                    ],
                    dayTimeStart: [
                        { required: true, message: '请选择有效日内时间范围', trigger: 'blur' }
                    ],
                    dayTimeEnd: [
                        { required: true, message: '请选择有效日内时间范围', trigger: 'blur' }
                    ],
                },
                noSingProjectList:noSingProjectList,
                submitDisabled:false,
                trafficOptions:trafficList,
                businessLineOptions:businessLineList,
                sourceOptions:mediumList,
                categoryOptions:clueCategoryList,
                industryOptions:industryCategoryList ,
                statusOptions: [{
                    value: 1,
                    name: '启用'
                }, {
                    value: 0,
                    name: '禁用'
                }],
                priorOptions: [{
                    value: 1,
                    name: '优先'
                }, {
                    value: 0,
                    name: '非优先'
                }],
                tags1: [],//包含搜索词
                tags2: [],//不包含搜索词
                tags3: [],//包含省
                tags4: [],//不包含省
            }        	  
        },
        methods: {
            changeSource(val){
                console.log(val)
            },
            changeDays(val){
                console.log(val)
                if(val=="0"){
                    this.showDays=false;
                }else{
                    this.showDays=true;
                }
            },
            unlimitedBtn(index, rows){                
                rows[index].unlimitedShow=true; 
                rows[index].unlimited="不限";
                rows[index].unlimitedVal="-1"; 
                rows[index].resourceMaxNum="0"; //为了不让校验而赋的无用的值  
                console.log(rows[index].unlimited);
                console.log(rows[index].unlimitedVal);                            
                console.log(rows[index].resourceMaxNum);                          
            },
            unlimitedIpt(index, rows){//点击不限input
                rows[index].unlimitedShow=false 
                rows[index].unlimited="";
                rows[index].unlimitedVal="";
                rows[index].resourceMaxNum="";                    
                console.log(rows[index].unlimited);
                console.log(rows[index].unlimitedVal);                            
                console.log(rows[index].resourceMaxNum);
            },
            submitForm(form) {
                this.$refs[form].validate((valid) => {
                    // 开始时间不能大于结束时间
                    var startTime=this.form.startTime;
                    var endTime=this.form.endTime;
                    if(endTime && startTime>endTime){
                        this.$message({
                            message: '结束时间不允许选择早于开始时间',
                            type: 'warning'
                        });
                        return;
                    }
                    // 开始时间不能大于结束时间
                    var dayTimeStart=this.form.dayTimeStart;
                    var dayTimeEnd=this.form.dayTimeEnd;
                    if(dayTimeEnd && dayTimeStart>dayTimeEnd){
                        this.$message({
                            message: '开始时间不能大于结束时间',
                            type: 'warning'
                        });
                        return;
                    }
                    if (valid) {
                    	var form = JSON.parse(JSON.stringify(this.form)); 
                        
                        // 不能选择重复电销组
                        var orgIdChoose=form.teleRuleTeamList; 
                        var ary=[];                   
                        for(var i=0;i<orgIdChoose.length;i++){
                        	var split=orgIdChoose[i].orgId.split(",");
                        	orgIdChoose[i].orgId=split[0];
                        	orgIdChoose[i].orgType=split[1];
                            ary.push(orgIdChoose[i].orgId);//把选择的值放入一个数组
                            var s = ary.join(",")+","; 
                            for(var j=0;j<ary.length;j++) {
                                if(ary[j]!=""){
                                    if(s.replace(ary[j]+",","").indexOf(ary[j]+",")>-1) {
                                        this.$message({
                                            message: '请不要选择相同的电销组/经纪组',
                                            type: 'warning'
                                        });
                                        return;
                                    }
                                }                                
                            }
                        }
                        // 不能选择重复话务组
                        orgIdChoose=form.trafficRuleTeamList; 
                        var ary=[];
                        for(var i=0;i<orgIdChoose.length;i++){
                        	var split=orgIdChoose[i].orgId.split(",");
                        	orgIdChoose[i].orgId=split[0];
                        	orgIdChoose[i].orgType=split[1];
                            ary.push(orgIdChoose[i].orgId);//把选择的值放入一个数组
                            var s = ary.join(",")+","; 
                            for(var j=0;j<ary.length;j++) {
                                if(ary[j]!=""){
                                    if(s.replace(ary[j]+",","").indexOf(ary[j]+",")>-1) {
                                        this.$message({
                                            message: '请不要选择相同的话务组/顾问组',
                                            type: 'warning'
                                        });
                                        return;
                                    }
                                }                                
                            }
                        }
                        var param=form;
                        param.ruleName=form.ruleName;
                        param.startTime=form.startTime;
                        param.endTime=form.endTime;
                        if(form.radio=="0"){
                            param.days="0"
                        }else{
                            param.days=this.form.days.join(',');
                        }
                        param.dayTimeStart=form.dayTimeStart;
                        param.dayTimeEnd=form.dayTimeEnd;
                        param.status=form.status;
                        param.teleList=form.teleRuleTeamList;
                        param.trafficList=form.trafficRuleTeamList;
                        param.source=form.source.join(',');
                        param.industryCategory=form.industryCategory.join(',');
                        param.category=this.form.category.join(',');
                        param.searchWord=this.tags1.join(',');
                        param.notSearchWord=this.tags2.join(',');
                        param.province=this.tags3.join(',');
                        param.notProvince=this.tags4.join(',');                        
                        aorVM.submitDisabled=true;
                        axios.post('/clueAssignRule/optRule/save', param)
	       	            .then(function (response) {
                               console.info(response);
	       	            	var data =response.data;
	       	            	if(data.code!="0"){
                                aorVM.$message(data.msg);
                                aorVM.submitDisabled=false;
	       	            	}else{
	       	            		aorVM.$message({message:'提交成功',type:'success',duration:1000,onClose:function(){
                                    aorVM.submitDisabled=false;
		       	                	document.location.href='/clueAssignRule/optRule/initRuleList';
	                      	    }});
	       	            	}
	       	            })
	       	            .catch(function (error) {
	       	            	aorVM.submitDisabled=false;
                            console.log(error);
	       	            });
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            deleteRow(index, rows) {//删除一行表格
                rows.splice(index, 1);
            },
            addFun1() {//添加包含搜索词
                let searchWord = this.form.searchWord;
                if (searchWord) {
                    this.tags1.push(searchWord);
                }
                this.form.searchWord = '';
            },
            deleteFun1(tag) {//删除包含搜索词
                this.tags1.splice(this.tags1.indexOf(tag), 1);
            },
            addFun2() {//添加不包含搜索词
                let notSearchWord = this.form.notSearchWord;
                if (notSearchWord) {
                    this.tags2.push(notSearchWord);
                }
                this.form.notSearchWord = '';
            },
            deleteFun2(tag) {//删除不包含搜索词
                this.tags2.splice(this.tags2.indexOf(tag), 1);
            },
            addFun3() {//添加包含省
                let province = this.form.province;
                if (province) {
                    this.tags3.push(province);
                }
                this.form.province = '';
            },
            deleteFun3(tag) {//删除包含省
                this.tags3.splice(this.tags3.indexOf(tag), 1);
            },
            addFun4() {//添加不包含省
                let notProvince = this.form.notProvince;
                if (notProvince) {
                    this.tags4.push(notProvince);
                }
                this.form.notProvince = '';
            },
            deleteFun4(tag) {//删除不包含省
                this.tags4.splice(this.tags4.indexOf(tag), 1);
            },
            addDomain() {
                console.log(businessLineList)
                // 取第一条
                var first=null;
                for(var i=0;i<businessLineList.length;i++){
                    first=businessLineList[0].businessLine;
                }
                var param ={};
            	  param.systemCode = "HUIJU";
            	  param.orgType = 1;
            	  param.businessLine = first;
                  console.info(param);
                  axios.post('/organization/organization/queryOrgByBusinessline', param)
                  .then(function (response) {
                        var result =  response.data;
                        console.info(result);
                        var table=result.data;
                        aorVM.form.teleRuleTeamList.push({
                            orgId: '',
                            businessLine: first,//业务线取第一条                 
                            teleOptions:table,                    
                            orgType: '',                    
                            proportion:'',
                            resourceMaxNum:'',
                            isPrior: 0,//默认非优先
                            orgDayTimeStart:'00:00:00',//新增时间段
                            orgDayTimeEnd:'23:59:59',//新增时间段
                            unlimited:'',//不限层
                            unlimitedVal:'',//不限层取值
                            unlimitedShow:false,//默认不显示
                        });
                  })
                  .catch(function (error) {
                       console.log(error);
                  });
                
            },
            addDomainTraffic() {
                console.log(trafficList)
                // 取第一条
                var first="";
                for(var i=0;i<trafficList.length;i++){
                    first=trafficList[0].id+","+trafficList[0].orgType;
                }
                this.form.trafficRuleTeamList.push({
                    orgId: first,                    
                    orgType: '',                    
                    proportion:'',
                    resourceMaxNum:'',
                    isPrior: 0,//默认非优先
                    orgDayTimeStart:'00:00:00',//新增时间段
                    orgDayTimeEnd:'23:59:59',//新增时间段
                    unlimited:'',//不限层
                    unlimitedVal:'',//不限层取值
                    unlimitedShow:false,//默认不显示
                });
            },
            resourceMaxNumber(index, rows){
                for(var i=0;i<rows.length;i++){                    
        　　      	  			rows[i].proportion=rows[i].proportion.replace(/[^\.\d]/g,'');
                    rows[i].proportion=rows[i].proportion.replace('.','');                    
                }
        　　		},
            resourceMaxNumber1(index, rows){
                for(var i=0;i<rows.length;i++){                    
        　　        				rows[i].resourceMaxNum=rows[i].resourceMaxNum.replace(/[^\.\d]/g,'');
                    rows[i].resourceMaxNum=rows[i].resourceMaxNum.replace('.','');                    
                }
        　　		}, 
        　　		cancelForm(){
            	document.location.href='/clueAssignRule/optRule/initRuleList';
            },
          //根据电销组查询电销总监
            getTeleGroupList(index,rows) {
              rows[index].orgId= '';
          	  var param ={};
          	  param.systemCode = "HUIJU";
          	  param.orgType = 1;
          	  param.businessLine = rows[index].businessLine;
                console.info(param);
                axios.post('/organization/organization/queryOrgByBusinessline', param)
                .then(function (response) {
                      var result =  response.data;
                      console.info(result);
                      var table=result.data;
                      rows[index].teleOptions= table;
                })
                .catch(function (error) {
                     console.log(error);
                });
            },
        },
        mounted(){
            document.getElementById('addOptimizeRule').style.display = 'block';
        }
    })
</script>
</html>